#include<stdio.h>
#include<stdlib.h>
int students=0;
int *studentList;

void read(){
	int flag=1;
	char c;
        int local=0;
	scanf("%d",&students);
        studentList=(int*)malloc(sizeof(int)*students);
		
	
}
void initArray(){
	int i=0;
	char ch;
	int local=0;
	for(i=0;i<students;i++){
		local=0;
		scanf("%d",&studentList[i]);
	}
}

void display(int *arr){
	int *ptr=arr;
	int i=0;
	for(i=0;i<students;i++){
		printf("%d\n",*ptr);
		ptr++;
	}
}
int process(){
	int *new=(int*)malloc(sizeof(int)*students);
	int i=0;
	int total=0;
	for(i=0;i<students;i++){
		new[i]=1;
	}

	for(i=0;i<students-1;i++){
		if(studentList[i]<studentList[i+1]){
			if(!(new[i+1]>new[i])){
				new[i+1]=new[i]+1;
			}
		}
		if(studentList[i]>studentList[i+1]){
			if(!(new[i]>new[i+1])){
				new[i]=new[i+1]+1;
			}
                }
	}

	for(i=students-1;i>0;i--){
		if(studentList[i]<studentList[i-1]){
			if(!(new[i-1]>new[i])){
				new[i-1]=new[i]+1;
			}
		}
		if(studentList[i-1]<studentList[i]){
			if(!(new[i]>new[i-1])){
				new[i]=new[i-1]+1;
			}
		}
	}
	for(i=0;i<students;i++){
		total=total+new[i];
	}

	return total;
}

int main(){
	
	read();
	initArray();
	printf("%d",process());
}


